//-------------------------------------------------------------------------------------
// <copyright file="ReceiveHandlerCollection.cs" company="Microsoft">
//      Copyright (c) 2003 Microsoft Corporation. All rights reserved.
//      THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
//      EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
//      WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// </copyright>
// <summary>
//      A collection of BizTalk 2004 objects.
// </summary>  
//-------------------------------------------------------------------------------------

namespace Microsoft.Sdc.Tasks.BizTalk2004.Configuration
{
	#region Using directives

	using System;
	using System.Collections;

	#endregion

	/// <summary>
	/// A collection of <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/> objects.
	/// </summary>
	internal class ReceiveHandlerCollection : CollectionBase
	{
		#region Constructors

		/// <summary>
		/// Creates a new collection of <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/> objects.
		/// </summary>
		public ReceiveHandlerCollection()
		{
		}

		#endregion

		#region Indexers

		/// <summary>
		/// Gets or sets the <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/> at a specified 
		/// position within the collection.
		/// </summary>
		/// <param name="index">
		/// The zero based index in the collection.
		/// </param>
		/// <value>
		/// A <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/>.
		/// </value>
		public ReceiveHandler this[int index]
		{
			get 
			{ 
				return (ReceiveHandler)this.List[index]; 
			}
			set 
			{ 
				this.List[index] = value; 
			}
		}

		/// <summary>
		/// Gets or sets the <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/> with
		/// a particular name.
		/// </summary>
		/// <param name="name">
		/// The name of the <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/>.
		/// </param>
		/// <value>
		/// A <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/>.
		/// </value>
		/// <exception cref="System.ArgumentNullException">
		/// Thrown when <paramref name="name"/> is <b>null</b> or zero length.
		/// </exception>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// Thrown when no object matching <paramref name="name"/> is found in the collection.
		/// </exception>
		public ReceiveHandler this[string name]
		{
			get 
			{ 
				int index = this.IndexOf(name);
				if (index >= 0)
				{
					return this[index];
				}
				else
				{
					throw new ArgumentOutOfRangeException("No object with the specified name was found.", name, "name");
				}
			}
			set 
			{ 
				int index = this.IndexOf(name);
				if (index >= 0)
				{
					this[index] = value;
				}
				else
				{
					throw new ArgumentOutOfRangeException("No object with the specified name was found.", name, "name");
				}
			}
		}

		#endregion

		#region Methods

		/// <summary>
		/// Adds a <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/> to the collection.
		/// </summary>
		/// <param name="handler">
		/// The <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/> to add.
		/// </param>
		public void Add(ReceiveHandler handler) 
		{
			this.List.Add(handler);
		}

		/// <summary>
		/// Gets whether a particular <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/>
		/// is contained in the collection.
		/// </summary>
		/// <param name="handler">
		/// The <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/> to check for.
		/// </param>
		/// <returns>
		/// <b>true</b> if <paramref name="handler"/> is contained in the collection, or <b>false</b> otherwise.
		/// </returns>
		public bool Contains(ReceiveHandler handler) 
		{
			return this.List.Contains(handler);
		}

		/// <summary>
		/// Gets whether a <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/> with the
		/// specified name is contained in the collection.
		/// </summary>
		/// <param name="name">
		/// The name of the <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/>.
		/// </param>
		/// <returns>
		/// <b>true</b> if an object with the name is contained in the collection, or <b>false</b> otherwise.
		/// </returns>
		public bool Contains(string name)
		{
			int index = this.IndexOf(name);
			return (index != -1);
		}

		/// <summary>
		/// Copies the collection into an <see cref="System.Array"/>.
		/// </summary>
		/// <param name="objects">
		/// The <see cref="System.Array"/> to copy the collection int.
		/// </param>
		/// <param name="index">
		/// The zero based index in the array at which to begin copying.
		/// </param>
		public void CopyTo(ReceiveHandler[] objects, int index) 
		{
			this.List.CopyTo(objects, index);
		}

		/// <summary>
		/// Gets the index of a <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/>.
		/// </summary>
		/// <param name="handler">
		/// The <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/> to get the index of.
		/// </param>
		/// <returns>
		/// The index of <paramref name="handler"/> if it is contained in the collection, or -1 otherwise.
		/// </returns>
		public int IndexOf(ReceiveHandler handler) 
		{
			return this.List.IndexOf(handler);
		}

		/// <summary>
		/// Retrieves the index of a <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/> from 
		/// the collection with the specified name.
		/// </summary>
		/// <param name="name">
		/// The name of the <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/>.
		/// </param>
		/// <returns>
		/// The index of the item if found, or -1 otherwise.
		/// </returns>
		public int IndexOf(string name)
		{
			if (name == null)
			{
				throw new ArgumentNullException("name");
			}
			for (int index = 0; index < this.List.Count; index++)
			{
				if (((ReceiveHandler)this.List[index]).Name == name)
				{
					return index;
				}
			}
			return -1;
		}

		/// <summary>
		/// Inserts a <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/> into the collection.
		/// </summary>
		/// <param name="index">
		/// The zero based index at which to insert <paramref name="handler"/>.
		/// </param>
		/// <param name="handler">
		/// The <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/> to insert.
		/// </param>
		public void Insert(int index, ReceiveHandler handler) 
		{
			this.List.Insert(index, handler);
		}

		/// <summary>
		/// Removes a <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/> from the collection.
		/// </summary>
		/// <param name="handler">
		/// The <see cref="Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceiveHandler"/> to remove.
		/// </param>
		public void Remove(ReceiveHandler handler) 
		{
			this.List.Remove(handler); 
		}

		#endregion
	}
}

